/**
 *@文件名称: AuthCodeUtil.java
 *注意：本内容仅限于悦畅科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
*/

package comchifaner.util;


/**
 * @Title: RandomPassWordUtil.java
 * @Description: 生成验证码
 */
public class RandomPassWordUtil {
    /**
     * @Description:创建指定数量的随机字符串
     * @param numberFlag
     * @param length
     * @return
     */
    public static String createRandom(boolean numberFlag, int length) {
        String retStr = "";
        String strTable = numberFlag ? "1234567890" : "1234567890abcdefghijkmnpqrstuvwxyz";
        int len = strTable.length();
        boolean bDone = true;
        do {
            retStr = "";
            int count = 0;
            for (int i = 0; i < length; i++) {
                double dblR = Math.random() * len;
                int intR = (int) Math.floor(dblR);
                char c = strTable.charAt(intR);
                if (('0' <= c) && (c <= '9')) {
                    count++;
                }
                retStr += strTable.charAt(intR);
            }
            if (count >= 1) {
                bDone = false;
            }
        }
        while (bDone);
        
        return retStr;
    }
    
    
    public static void main(String[] args) {
        System.out.println(RandomPassWordUtil.createRandom(true, 6));
    }
    
   
}
